<template>
  <el-form
    :model="ruleForm"
    :rules="rules"
    ref="ruleForm"
    label-width="100px"
    class="demo-ruleForm"
  >
    <el-form-item label="活动名称" prop="title">
      <el-input v-model="ruleForm.title"></el-input>
    </el-form-item>
    <el-form-item label="活动简介" prop="intro">
      <el-input v-model="ruleForm.intro"></el-input>
    </el-form-item>
    <el-form-item label="活动详情" prop="detail">
      <el-input type="textarea" v-model="ruleForm.detail"></el-input>
    </el-form-item>
    <el-form-item label="活动封面" prop="poster">
      <el-input v-model="ruleForm.poster"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm('ruleForm')"
        >立即创建</el-button
      >
      <el-button @click="resetForm('ruleForm')">重置</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
import {activityAdd} from '../../api/job'
export default {
  data() {
    return {
      ruleForm: {
        title:'测试活动名称',
        intro:'测试活动简介',
        detail:'测试活动详情,测试活动详情,测试活动详情',
        poster:'img.png'
      },
      rules: {
        title: [
          { required: true, message: "请输入活动名称", trigger: "blur" }
        ],
        intro: [
          { required: true, message: "请输入活动简介", trigger: "blur" },
        ],
        detail: [
          { required: true, message: "请输入活动详情", trigger: "blur" },
        ],
        poster: [
          { required: true, message: "请上传图片", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          activityAdd(this.ruleForm).then(res=>{
            this.$message({
              type:'success',
              message:'新增成功'
            })
          })
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>
